package LearnDataStructure.a_线性结构.列表.链表;

import org.junit.Assert;
import org.junit.Test;

import static org.junit.Assert.*;

/**
 * @version: 1.0
 * @Author: wuqiu
 * @date: 2023-07-01 17:10
 * @description: LeetcodeLearnAlgorithm -> LearnDataStructure.a_线性结构.列表.链表
 */
public class MyLinkedListSingleTest1 {

    @Test
    public void add() {
        MyLinkedListSingle myLinkedListSingle = new MyLinkedListSingle();
        myLinkedListSingle.add("王");
        myLinkedListSingle.add("英");
        myLinkedListSingle.add("龙");
        System.out.println(myLinkedListSingle);
    }

    @Test
    public void delete() {
        MyLinkedListSingle myLinkedListSingle = new MyLinkedListSingle();
        myLinkedListSingle.add("王");
        myLinkedListSingle.add("英");
        myLinkedListSingle.add("龙");
        myLinkedListSingle.delete("龙");
        System.out.println(myLinkedListSingle);
    }

    @Test
    public void testDelete() {
        MyLinkedListSingle myLinkedListSingle = new MyLinkedListSingle();
        myLinkedListSingle.add("王");
        myLinkedListSingle.add("英");
        myLinkedListSingle.add("龙");
        myLinkedListSingle.delete(0);
        System.out.println(myLinkedListSingle);
        Assert.assertEquals(myLinkedListSingle.toString(),"[英 , 龙] size = 2");
    }

    @Test
    public void update() {
        MyLinkedListSingle myLinkedListSingle = new MyLinkedListSingle();
        myLinkedListSingle.add("王");
        myLinkedListSingle.add("英");
        myLinkedListSingle.add("龙");
        myLinkedListSingle.update(0,"A");
        System.out.println(myLinkedListSingle);
        Assert.assertEquals(myLinkedListSingle.toString(),"[A , 英 , 龙] size = 3");
    }

    @Test
    public void contains() {
        MyLinkedListSingle myLinkedListSingle = new MyLinkedListSingle();
        myLinkedListSingle.add("王");
        myLinkedListSingle.add("英");
        myLinkedListSingle.add("龙");
        boolean bole = myLinkedListSingle.contains("王");
        Assert.assertEquals(bole,true);
    }

    @Test
    public void atElement() {
        MyLinkedListSingle myLinkedListSingle = new MyLinkedListSingle();
        myLinkedListSingle.add("王");
        myLinkedListSingle.add("英");
        myLinkedListSingle.add("龙");
        Object element = myLinkedListSingle.AtElement(0);
        Assert.assertEquals(element,"王");
    }

    @Test
    public void indexOf() {
        MyLinkedListSingle myLinkedListSingle = new MyLinkedListSingle();
        myLinkedListSingle.add("王");
        myLinkedListSingle.add("英");
        myLinkedListSingle.add("龙");
        int i = myLinkedListSingle.indexOf("龙");
        Assert.assertEquals(i,2);
    }

    @Test
    public void iter() {
        MyLinkedListSingle<String> myLinkedListSingle = new MyLinkedListSingle<String>();
        myLinkedListSingle.add("王");
        myLinkedListSingle.add("英");
        myLinkedListSingle.add("龙");
        while (myLinkedListSingle.hasNext()) {
            System.out.println(myLinkedListSingle.next());
        }
    }
}